<script language="javascript">
function validasi(form){
  if (form.nama.value == ""){
    alert("Anda belum mengisikan Username.");
    form.nama.focus();
    return (false);
  }
     
  if (form.tempat_lahir.value == ""){
    alert("Anda belum mengisikan Password.");
    form.tempat_lahir.focus();
    return (false);
  }
  return (true);
}
</script>
<body OnLoad="document.mahasiswa.nama.focus();" >
<?php
$aksi="module/mahasiswa/aksi.php";
switch($_GET[act]){
  // Tampil Berita
  default:
?>
<h2>Mahasiswa</h2>
<?php echo "<input type=button value='Tambah Mahasiswa' onclick=\"window.location.href='?mod=mahasiswa&act=tambahmahasiswa';\">"; ?>
<table width="490" >
  <tr >
    <th width="20">No</th>
    <th width="144">npk</th>
    <th width="150">Nama</th>
     <th width="150">Jurusan</th>
    <th width="156">Aksi</th>
  </tr>
 <?php 
 
 	$p      = new Paging;
    $batas  = 5;
    $posisi = $p->cariPosisi($batas);
 
 		$sql="select * from mahasiswa ORDER BY npk DESC LIMIT $posisi,$batas ";
 		$query=@mysql_query($sql);
	$no=1 + $posisi;
		while ($data=@mysql_fetch_array($query)){
  ?>
   <tr class="<?php if ($no %2 == 0):echo "zebra";else:echo "zebra2"; endif;?>" align="center">
    <td><?=$no;?></td>
    <td><?=$data['npk'];?></td>
     <td><?=$data['nama'];?></td>
      <td><?php $jurusan=substr($data['npk'],0,2);
	  		if($jurusan==10){
			echo "D3 Akutansi";
			}
			elseif($jurusan==11){
			echo "S1 Akutansi";
			}
			elseif($jurusan==21){
			echo "S1 Manajemen";
			}
			elseif($jurusan==30){
			echo "D3 Perdagangan";
			}			
	  ?></td>
     <td align="center"><a href=?mod=mahasiswa&act=editmahasiswa&id=<?php echo "$data[npk]"; ?>>Edit </a>| 
     <?php echo "<a href=$aksi?mod=mahasiswa&act=hapus&id=$data[npk]&namafile=$data[foto]>"; ?>Hapus</a> </td>
  </tr>
  
 <?php 
 $no++;
 } ?>
</table>
<center><?php 
    $jmldata = mysql_num_rows(mysql_query("SELECT * FROM mahasiswa"));
    $jmlhalaman  = $p->jumlahHalaman($jmldata, $batas);
    $linkHalaman = $p->navHalaman($_GET[halaman], $jmlhalaman);

    echo "<div id=paging>$linkHalaman</div><br>";
break;
  case "tambahmahasiswa":
  ?>
  <h2>Tambah  Mahasiswa</h2>
 
<?php
 //onSubmit='return validasi(this)'
 echo "
 <form name=mahasiswa method=POST  action='$aksi?mod=mahasiswa&act=input'  enctype='multipart/form-data'>"; 
  ?>
<table width="668" >
   
  
<tr>
      <td width="203">Nama Mahasiswa*</td>
    
    <td width="453"><input type=text name='nama' size=50></td>
   
  </tr>
    <tr>
      <td width="203">Tempat Lahir*</td>
    
      <td width="453"><input type=text name='tempat_lahir' size=20></td>
   
  </tr>
    <tr>
      <td width="203">Tanggal Lahir*</td>
    
<td width="453">	<select name="tanggal" style="width:50px">
			<?PHP
			$tanggal = 1; #tanggal awal 1
			while ($tanggal!=32){ #ketika value dari $tanggal tidak sama dengan 32 maka lakukan perulangan sampai ke 32
			echo "<option>$tanggal</option>"; #memunculkan tanggal dari 1 - 31
			$tanggal++; #munculkan  tanggal di form
			}
			?>
			</select>
			<select name="bulan" style="width:70px">
			<option>Jan</option>
			<option>Feb</option>
			<option>Mar</option>
			<option>Apr</option>
			<option>Mei</option>
			<option>Jun</option>
			<option>Jul</option>
			<option>Ags</option>
			<option>Sep</option>
			<option>Okt</option>
			<option>Nov</option>
			<option>Des</option>
			</select>
			<select name="tahun" style="width:72px">
			<?PHP
			$tahun = 1970; #tahun awal 1970
			while ($tahun!=date('Y') + 1){
			echo "<option>$tahun</option>";
			$tahun++;
			}
			?>
	  </select></td>
   
  </tr>
    <tr>
      <td width="203" >Alamat*</td>
    

      <td width="453"><textarea name="alamat" class="alamat"></textarea></td>
   
  </tr>
    <tr>
      <td width="203">Rt/Rw</td>
    
      <td width="453"><input type=text name='rtrw' size=20></td>
   
  </tr>
    <tr>
      <td width="203">Kota*</td>
    
      <td width="453"><input type=text  name='kota' size=40></td>
   
  </tr>
    <tr>
      <td width="203">Kode Pos</td>
    
      <td width="453"><input type=text  name='kodepos' size=6></td>
   
  </tr>
    <tr>
      <td width="203">Telepon</td>
    
      <td width="453"><input type=text  name='telp' size=12></td>
   
  </tr>
    <tr>
      <td width="203">email</td>
    
      <td width="453"><input type=text  name='email' size=40></td>
   
  </tr>
    <tr>
      <td width="203">Jenis Kelamin*</td>
    
      <td width="453"></select>
<select name="kelamin" style="width:170px">
			<option value="L">Laki-Laki</option>
			<option value="P">Perempuan</option>
	  </select></td>
   
  </tr>
    <tr>
      <td width="203">Agama*</td>
    
      <td width="453"></select>
		<select name="agama" style="width:170px">
		  <option value="Islam">Islam</option>
		  <option value="Katholik">Katholik</option>
		  <option value="Protestan">Protestan</option>
		  <option value="Hindu">Hindu</option>
		  <option value="Budha">Budha</option>
          <option value="Konghuchu">Konghuchu</option>
	  </select></td>
   
  </tr>
     <tr>
      <td width="203">Jurusan*</td>
    
<td width="453"><select name="jurusan" style="width:150px">
			<?PHP
			$sql="select * from ms_jurusan";
			$query=@mysql_query($sql);
			
			while ($j=@mysql_fetch_array($query)){
			echo "<option value=$j[kode_jurusan] >$j[nama_jurusan]</option>";
			
			}
			?>
	   </select></td>
   
  </tr>
     <tr>
      <td width="203">Angkatan/ Tahun Masuk*</td>
    
<td width="453"><select name="angkatan" style="width:72px">
			<?PHP
			$tahun = 2000; 
			while ($tahun!=date('Y') + 1){
			echo "<option>$tahun</option>";
			$tahun++;
			}
			?>
	   </select></td>
   
  </tr>
     <tr>
      <td width="203">Kode kampus*</td>
    
      <td width="453"></select>
  <select name="kode" style="width:170px">
  <?php $sql="select * from kode_kampus";
  		$query=@mysql_query($sql);
		while($r=@mysql_fetch_array($query)){  
		
		echo "<option value=$r[kode_kampus]>$r[penjelasan]</option>";
  }
  ?>
	  </select></td>
   
  </tr>
     <tr>
      <td width="203">Foto Mahasiswa</td>
    
      <td width="453"><input type=file  name='fupload' size=40></td>
   
  </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type=submit value=Simpan>
                            <input type=button value=Batal onclick=self.history.back()></td>
     
    </tr>
  </table>
</form>
  
<?php break; 
 case "editmahasiswa":
 ?>
<h2>Edit Mahasiswa</h2>
 
<?php
 //onSubmit='return validasi(this)'
 echo "
 <form name=mahasiswa method=POST  action='$aksi?mod=mahasiswa&act=update'  enctype='multipart/form-data'>"; 

$sql="select * from mahasiswa where npk='$_GET[id]'";
$query=@mysql_query($sql);
$r=@mysql_fetch_array($query);

  ?>
<input type=hidden  name='id' value="<?php  echo $r['npk']; ?>"size=6
  <center>
  <table width="533" >
  <input type=hidden name='npk' value="<?php  echo $r['npk']; ?>" >
   <tr>
      <td colspan="2" align="center"><img src="../mahasiswa/foto_mahasiswa/<?php  echo $r['foto']; ?>" width="115" height="124" /></td>
    </tr>
    <tr>
      <td width="197">NPK</td>
    
      <td width="324"><input type=text name='noreg' value="<?php  echo $r['npk']; ?>" readonly="readonly"  size=20>
      <input type=hidden name='npk' value="<?php  echo $r['npk']; ?>"</td>
    </tr>
    <tr>
      <td width="197">Nama Mahasiswa*</td>
    
      <td width="324"><input type=text name='nama' value="<?php  echo $r['nama']; ?>" size=50></td>
    </tr>
    <tr>
      <td width="197">Tempat Lahir*</td>
    
      <td width="324"><input type=text name='tempat_lahir'  value="<?php  echo $r['tempat_lahir']; ?>" size=20></td>
    </tr>
    <tr>
      <td width="197">Tanggal Lahir*</td>
    
  <td width="324">	<select name="tanggal" style="width:50px">
			<?PHP
			$tanggal = 1; #tanggal awal 1
			while ($tanggal!=32){ 
			echo "<option>$tanggal</option>"; 
			$tanggal++; 
			}
			?>
			</select>
    <select name="bulan2" style="width:70px">
      <option>Jan</option>
      <option>Feb</option>
      <option>Mar</option>
      <option>Apr</option>
      <option>Mei</option>
      <option>Jun</option>
      <option>Jul</option>
      <option>Ags</option>
      <option>Sep</option>
      <option>Okt</option>
      <option>Nov</option>
      <option>Des</option>
    </select>
<select name="tahun" style="width:72px">
			<?PHP
			$tahun = 1970; #tahun awal 1970
			while ($tahun!=date('Y') + 1){
			echo "<option>$tahun</option>";
			$tahun++;
			}
			?>
	  </select></td>
    </tr>
    <tr>
      <td width="197">Alamat*</td>
    
      <td width="324"><textarea name="alamat" class="alamat" ><?php  echo $r['alamat']; ?></textarea></td>
    </tr>
    <tr>
      <td width="197">Rt/Rw</td>
    
      <td width="324"><input type=text name='rtrw' value="<?php  echo $r['rtrw']; ?>"size=20></td>
    </tr>
    <tr>
      <td width="197">Kota*</td>
    
      <td width="324"><input type=text  name='kota' value="<?php  echo $r['kota']; ?>" size=40></td>
    </tr>
    <tr>
      <td width="197">Kode Pos</td>
    
      <td width="324"><input type=text  name='kodepos' value="<?php  echo $r['kode_pos']; ?>"size=6></td>
    </tr>
    <tr>
      <td width="197">Telepon</td>
    
      <td width="324"><input type=text  name='telp' value="<?php  echo $r['telepon']; ?>" size=12></td>
    </tr>
    <tr>
      <td width="197">email</td>
    
      <td width="324"><input type=text  name='email' value="<?php  echo $r['email']; ?>" size=40> </td>
    </tr>
    <tr>
      <td width="197">Jenis Kelamin*</td>
    
      <td width="324"><?php 
	   	$sex=$r[jenis_kelamin];
		if ($sex=='L') $k1="selected";
		else $k2="selected";
		
	  echo " <SELECT name=sex>
					<OPTION $k1 value=L>Laki-laki<OPTION $k2 value=P>
					Perempuan</OPTION></SELECT>";
			
          ?></td>
    </tr>
    <tr>
      <td width="197">Agama*</td>
    
      <td width="324"></select>
        <select name="agama2" style="width:170px">
          <option value="Islam">Islam</option>
          <option value="Katholik">Katholik</option>
          <option value="Protestan">Protestan</option>
          <option value="Hindu">Hindu</option>
          <option value="Budha">Budha</option>
          <option value="Konghuchu">Konghuchu</option>
        </select></td>
    </tr>
     <tr>
      <td width="197">Jurusan*</td>
    
  <td width="324"><?PHP
					
			echo"<select name='jurusan'>";
 
          $tampil=mysql_query("SELECT * FROM ms_jurusan ORDER BY kode_jurusan");
          if ($r[kode_jurusan]==0){
            echo "<option value=0 selected>- Pilih Kategori -</option>";
          }   

          while($w=mysql_fetch_array($tampil)){
            if ($r[jurusan]==$w[id_kategori]){
              echo "<option value=$w[kode_jurusan] selected>$w[nama_jurusan]</option>";
            }
            else{
              echo "<option value=$w[kode_jurusan]>$w[nama_jurusan]</option>";
            }
          }
		 

    echo "</select>";
			
		
			?>
	   </select></td>
    </tr>
     <tr>
      <td width="197">Angkatan/ Tahun Masuk*</td>
    
  <td width="324"><select name="angkatan" style="width:72px">
    <?PHP
			$tahun = 2000; 
			while ($tahun!=date('Y') + 1){
			echo "<option>$tahun</option>";
			$tahun++;
			}
			
			?>
  </select></td>
    </tr>
     <tr>
      <td width="197">Kode kampus*</td>
    
      <td width="324"></select>
  <select name="kode" style="width:170px">
  <?php $sql="select * from kode_kampus";
  		$query=@mysql_query($sql);
		while($r=@mysql_fetch_array($query)){  
		
		echo "<option value=$r[kode_kampus]>$r[penjelasan]</option>";
  }
  ?>
	  </select></td>
    </tr>
     <tr>
      <td width="197">Foto Mahasiswa</td>
    
      <td width="324"><input type=file  name='fupload' size=40></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type=submit value=Simpan>
                            <input type=button value=Batal onclick=self.history.back()></td>
    </tr>
  </table>
</form>
 <?php break; ?>
<?php } ?>

</body>